SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[ClientesUpdateCommand]
(
	@ID numeric(10, 0),
	@CLIENTE varchar(150),
	@NOMBRE_COMERCIAL varchar(150),
	@DIRECCION varchar(100),
	@ID_CIUDAD numeric(10, 0),
	@ID_VENDEDOR numeric(10, 0),
	@RNC varchar(11),
	@TELEFONO varchar(14),
	@CELULAR varchar(14),
	@FAX varchar(14),
	@OTRO varchar(14),
	@EMAIL varchar(80),
	@FECHA datetime2,
	@OBSERVACIONES varchar(150),
	@LIMITE_CREDITO numeric(10, 2),
	@ACTIVO bit,
	@ID_CATEGORIA numeric(10, 0),
	@ID_ZONA numeric(10, 0),
	@ID_RUTA numeric(10, 0),
	@ID_FORMA_PAGO numeric(10, 0),
	@IMPUESTOS bit,
	@MONTO_ADEUDADO numeric(10,2),
	@Original_ID numeric(10, 0),
	@Original_CLIENTE varchar(150),
	@Original_NOMBRE_COMERCIAL varchar(150),
	@Original_DIRECCION varchar(100),
	@Original_ID_CIUDAD numeric(10, 0),
	@Original_ID_VENDEDOR numeric(10, 0),
	@Original_RNC varchar(11),
	@Original_TELEFONO varchar(14),
	@IsNull_CELULAR Int,
	@Original_CELULAR varchar(14),
	@IsNull_FAX Int,
	@Original_FAX varchar(14),
	@IsNull_OTRO Int,
	@Original_OTRO varchar(14),
	@IsNull_EMAIL Int,
	@Original_EMAIL varchar(80),
	@Original_FECHA datetime2,
	@IsNull_OBSERVACIONES Int,
	@Original_OBSERVACIONES varchar(150),
	@IsNull_LIMITE_CREDITO Int,
	@Original_LIMITE_CREDITO numeric(10, 2),
	@Original_ACTIVO bit,
	@Original_ID_CATEGORIA numeric(10, 0),
	@IsNull_ID_ZONA Int,
	@Original_ID_ZONA numeric(10, 0),
	@IsNull_ID_RUTA Int,
	@Original_ID_RUTA numeric(10, 0),
	@Original_ID_FORMA_PAGO numeric(10, 0),
	@Original_IMPUESTOS bit
)
AS
	SET NOCOUNT OFF;
UPDATE [CLIENTES] SET [ID] = @ID, [CLIENTE] = @CLIENTE, [NOMBRE_COMERCIAL] = @NOMBRE_COMERCIAL, [DIRECCION] = @DIRECCION, [ID_CIUDAD] = @ID_CIUDAD, [ID_VENDEDOR] = @ID_VENDEDOR, [RNC] = @RNC, [TELEFONO] = @TELEFONO, [CELULAR] = @CELULAR, [FAX] = @FAX, [OTRO] = @OTRO, [EMAIL] = @EMAIL, [FECHA] = @FECHA, [OBSERVACIONES] = @OBSERVACIONES, [LIMITE_CREDITO] = @LIMITE_CREDITO, [ACTIVO] = @ACTIVO, [ID_CATEGORIA] = @ID_CATEGORIA, [ID_ZONA] = @ID_ZONA, [ID_RUTA] = @ID_RUTA, [ID_FORMA_PAGO] = @ID_FORMA_PAGO, [IMPUESTOS] = @IMPUESTOS, [MONTO_ADEUDADO]= @MONTO_ADEUDADO WHERE (([ID] = @Original_ID) AND ([CLIENTE] = @Original_CLIENTE) AND ([NOMBRE_COMERCIAL] = @Original_NOMBRE_COMERCIAL) AND ([DIRECCION] = @Original_DIRECCION) AND ([ID_CIUDAD] = @Original_ID_CIUDAD) AND ([ID_VENDEDOR] = @Original_ID_VENDEDOR) AND ([RNC] = @Original_RNC) AND ([TELEFONO] = @Original_TELEFONO) AND ((@IsNull_CELULAR = 1 AND [CELULAR] IS NULL) OR ([CELULAR] = @Original_CELULAR)) AND ((@IsNull_FAX = 1 AND [FAX] IS NULL) OR ([FAX] = @Original_FAX)) AND ((@IsNull_OTRO = 1 AND [OTRO] IS NULL) OR ([OTRO] = @Original_OTRO)) AND ((@IsNull_EMAIL = 1 AND [EMAIL] IS NULL) OR ([EMAIL] = @Original_EMAIL)) AND ([FECHA] = @Original_FECHA) AND ((@IsNull_OBSERVACIONES = 1 AND [OBSERVACIONES] IS NULL) OR ([OBSERVACIONES] = @Original_OBSERVACIONES)) AND ((@IsNull_LIMITE_CREDITO = 1 AND [LIMITE_CREDITO] IS NULL) OR ([LIMITE_CREDITO] = @Original_LIMITE_CREDITO)) AND ([ACTIVO] = @Original_ACTIVO) AND ([ID_CATEGORIA] = @Original_ID_CATEGORIA) AND ((@IsNull_ID_ZONA = 1 AND [ID_ZONA] IS NULL) OR ([ID_ZONA] = @Original_ID_ZONA)) AND ((@IsNull_ID_RUTA = 1 AND [ID_RUTA] IS NULL) OR ([ID_RUTA] = @Original_ID_RUTA)) AND ([ID_FORMA_PAGO] = @Original_ID_FORMA_PAGO) AND ([IMPUESTOS] = @Original_IMPUESTOS));
	
SELECT * FROM CLIENTES WHERE (ID = @ID)
GO
